package com.aaa.util;

import com.aaa.entity.BackExpenseorder;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

/**
 * @ClassName OrderNum
 * @Description TODO
 * @Author caolinlin
 * @Date 2018/12/25 13:22
 **/
public class OrderNum {

    public static String createOrderNumber(){
        //格式化日期为"yymmdd"
        DateFormat format = new SimpleDateFormat("yyMMdd");
        Date date = new Date();
        StringBuffer buffer = new StringBuffer();
        buffer.append(format.format(date));
        buffer.append((date.getTime() + "").substring(9));
        buffer.append(getRandNum(4));
        return buffer.toString();
    }
    /**
     * 获取四位随机数
     * @param leng  随机数长度
     * @return
     */
    public static String getRandNum(int leng){
        Random random = new Random();
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < leng; i++) {
            result.append(random.nextInt(10));
        }
        if(result.length()>0){
            return result.toString();
        }
        return null;
    }



}
